<#assign contextPath=springMacroRequestContext.getContextPath() />
<#import "/public/frame/main.html" as frame />
<@frame.head "南航明珠商城-系统管理">
</@frame.head>
<div class="page-container">
	<form action="${contextPath}/employee/employee_save" method="post" class="form form-horizontal" id="form-employee">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				员工姓名：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="name" name="name" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				入职时间：</label>
			<div class="formControls col-xs-6 col-sm-6">
			<input  type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\'empDate\')||\'%y-%M-%d\'}',readOnly: true })" id="empDate" 
                name="empDate"  class="input-text Wdate" style="width:120px;">
				
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				手机号：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="mobile" name="mobile" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				座机：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="phone" name="phone" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				性别：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<span class="select-box radius">
	           <select class="select"  name="sex" id="sex">
		           <option value="1">男</option> 
		           <option value="2">女</option> 
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				年龄：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="age" name="age" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				办公地址：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="address" name="address" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				状态：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<span class="select-box radius">
	           <select class="select"  name="state" id="state">
		           <option value="1">在职</option> 
		           <option value="2">离职</option> 
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				备注：</label>
			<div class="formControls col-xs-6 col-sm-6">
				<input type="text" class="input-text" value="" placeholder="" id="remark" name="remark" >
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				机构名：</label>
			<div class="formControls col-xs-6 col-sm-6">
					           <span class="select-box radius">
	           <select class="select"  name="organizationId" id="organizationId">
	           <option value>请选择机构</option>
	             <#list organizationList as list>  
	                 <option value="${list.id?c}">${list.name}</option>
	             </#list>
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2">
				<span class="c-red">*</span>
				部门名：</label>
			<div class="formControls col-xs-6 col-sm-6">
					           <span class="select-box radius">
	           <select class="select"  name="departmentId" id="departmentId" disabled="disabled">
	           <option value="-1">请先选择部门</option> 
	           </select>
	           </span>
			</div>
		</div>
		<div class="row cl">
			<div class="col-9 col-offset-2">
				<input class="btn btn-primary radius" type="button" onclick="save();"  value="&nbsp;&nbsp;增加&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</div>
<@frame.end "default">
</@frame.end>
<script type="text/javascript" src="${contextPath}/resources/lib/zTree/v3/js/jquery.ztree.core-3.5.min.js"></script>
<script type="text/javascript" src="${contextPath}/resources/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script> 
<script type="text/javascript" src="${contextPath}/resources/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript">
var path="${contextPath}";
$(document).ready(function(){
    //顶级分类方法
  $("#organizationId").change(function(){
	   
	           $("#departmentId").removeAttr("disabled");
	           		var id = $('#organizationId').val();
	           		if(id == 0){
		           		$("#departmentId").attr("disabled", "disabled");
		           	  	$("#departmentId").empty();
		           	 	$("#departmentId").prepend("<option value='-1'>请先选择部门</option>");
		           	 	return false;
	           		}
	           		  var url=path+"/employee/query_department_list?id="+id;
			           $.post(url,'',function(msg){
				           if(msg!="notfound")
				           {  
						     $("#departmentId").html(msg);    
				           }
			          });
	            });
});
// 电话正则判断
function IsTelephone(obj)
{ 
	var pattern=/(^[0-9]{3,4}\-[0-9]{7,8}$)|(^[0-9]{3,4}\-[0-9]{7,8}\-[0-9]{3,8}$)/; 
	if(pattern.test(obj)) 
	{ 
		return true; 
	} else { 
		return false; 
	} 
}	
//验证手机
function checkPhone(mobilPhone){
	var isMobilPhone = /^1[3,4,5,8]\d{9}$/.test(mobilPhone);
	if(isMobilPhone){
		return true;
	}else{
		return false;	
	}
}
 //正数验证
function checkNum(e){
	var parm=e;
	var vArr = parm.match(/^[0-9]+$/);
	if(vArr==null){
		return false;
	}else{
		return true;
	}
}
function save(){
	var name=$("#name").val();
    var dateEmp=$("#empDate").val(); 
    var mobile=$("#mobile").val();
    var phone=$("#phone").val();
	var age=$("#age").val();
	var address=$("#address").val();
	var remark=$("#remark").val();
	var orgid=$("#organizationId").val();
	var dept=$("#departmentId").val();
	var sex=$("#sex").val();
	var status=$("#status").val();
	//验证只包含字母或者汉字
var pattern1 =/(^[\u4e00-\u9fa5A-Za-z]*$)/;

	   if(name.length==0){
		   layer.alert("请输入姓名");
          document.typeForm.name.focus();
          return false;
       }
	 if (!pattern1.test(name)) {
		 layer.alert("请输入合法的姓名！");
	     	   document.typeForm.name.focus();
	       	   return false;
  	   }
  	   
       if(dateEmp.length==0){
    	   layer.alert("请输入入职时间");
          document.typeForm.dateEmp.focus();
          return false;
       }
      var patternMobile =/(^[0-9,]*$)/;
       if(mobile.length==0||!patternMobile.test(mobile)){
    	   layer.alert("请输入正确的手机号码");
          document.typeForm.mobile.focus();
          return false;
       }     	      
       if(phone.length==0||!IsTelephone(phone)){
    	   layer.alert("请输入座机号码，区号-电话号码");
          return false;
       }
       if(age.length==0){
    	   layer.alert("请输入年龄");
          document.typeForm.age.focus();
          return false;
       }

       if(age < 15 || age > 150 || !checkNum(age)){
    	   layer.alert("年龄只能在16-150之间！");
	      document.typeForm.age.focus();
	      return false;
	   }
       
       if(address.length==0){
    	   layer.alert("请输入地址");
	       document.typeForm.address.focus();
          return false;
       }
       	if(sex=="0"){
       		layer.alert("请选择性别！")
     		return false;
     	}
     	if(status=="0"){
     		layer.alert("请选择状态！")
     		return false;
     	}
     	if(orgid==""){
     		layer.alert("请选择机构！")
     		return false;
     	}
     
    	if(dept==""){
    		layer.alert("请选择部门！")
     		return false;
     	}	
    $("#form-employee").ajaxSubmit({
		dataType : 'html',
        success: function(message){
        		if(message == "200"){
                    layer.msg('操作成功!',{icon:1,time:1000},function(){
/*                         var index = parent.layer.getFrameIndex(window.name);
                        parent.query_brand_form.submit();
                        parent.layer.close(index); */
                        parent.window.location.reload();
                    });
 				}else if(message == "500"){
 					layer.alert("系统繁忙！");
 				}else{
 					layer.alert(message);
 				}
        },
        error: function(){
            layer.msg('操作失败!',{icon:5,time:1000});
        }
    });
}
function trim(str){ 
	 return str.replace(/(^\s*)|(\s*$)/g, "");
	}
</script>
</body>
</html>